home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Frameworks / Hsoi's App Shell 1.0a4 / Hsoi's App Shell Source / HASUtilPrint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-21  |  3.6 KB  |  124 lines  |  [TEXT/CWIE]

  1. /*
  2.     HASUtilPrint.c from Hsoi's App Shell © 1995-1997 John C. Daub. All Rights Reserved.
  3.  
  4.     This file is a wee different than the rest of the shell.  (Currently) this file
  5.     contains only one function, HsoiSetSpacing.  This function manipulates some of
  6.     the inner data structures on a WASTE instance (namely the LineArrayHandle in
  7.     the WERec).
  8.     
  9.     This is nice and fun because it allows us to print the text double-spaced (this
  10.     function is only used during the printing loop to create a double-spaced print out,
  11.     and this function is ONLY used upon a clone of the original WE instance.  do
  12.     NOT use this function on your original WE instance else suffer the possible
  13.     consequences).  If you happen to do that, WECalText MIGHT be able to fix it
  14.     for you, but no guarentees.
  15.     
  16.     anyways, since this function manipulates some private WASTE stuff, we have
  17.     to #include WASTEIntf.h instead of WASTE.h, and we also must put this function
  18.     in a file seperate from the rest of the shell.
  19.     
  20.     Also notice that we declare the function prototype here (with a WEHandle for
  21.     WASTEIntf.h compatability), but then "redeclare" it in HASUtilPrint.h
  22.     (with a WEReference).  The first is to force no compiler errors/warnings.
  23.     the second, to allow this fuction to be called by other functions in the
  24.     shell.
  25.     
  26.     Hopefully this all makes sense.
  27.     
  28.     This routine was based upon the Pascal Tex-Edit+ 1.6.3 source by Tom
  29.     Bender.  I translated it to C (with the help of Ken Long, Dan Crevier,
  30.     and John Solhurst...the last line was a pain...all 3 of these guys
  31.     tried it, and Dan's was the closest...it actually compiled but was
  32.     a little off...it was an easy fix).
  33.  
  34.     I've left the original Pascal code in just in case someone might
  35.     spot an error :)
  36.     
  37. */
  38.  
  39. #pragma mark ••• #includes •••
  40.  
  41. #include "WASTEIntf.h"
  42. // note:  HASUtilPrint.h isn't #included here...see above for why.  instead,
  43. // here's the only function prototype we need.
  44.  
  45. #pragma mark -
  46. #pragma mark ••• Function Prototypes •••
  47.  
  48. void HsoiSetSpacing( WEHandle we );
  49.  
  50. #pragma mark -
  51.  
  52. // here's the original Pascal version
  53.  
  54. /*
  55. procedure SetSpacing (txtHdl: WEHandle);
  56.  
  57. { This procedure is called by DoPrint to double the line spacing for printing. }
  58.  
  59.     var
  60.         x: longint;
  61.         theLineCount: longint;
  62.         theLineArrayHandle: LineArrayHandle;
  63.  
  64.     begin            { SetSpacing }
  65.         theLineCount := WECountLines(txtHdl);
  66.         theLineArrayHandle := tWEHandle(txtHdl)^^.hLines;
  67.         for x := 1 to theLineCount do
  68.             theLineArrayHandle^^[x].lineOrigin := 2 * theLineArrayHandle^^[x].lineOrigin
  69.     end;            { end of SetSpacing }
  70. */
  71.  
  72.  
  73. // here is the C translation
  74.  
  75. void    HsoiSetSpacing( WEHandle we )
  76. {
  77.     long                x;
  78.     long                lineCount;
  79.     WELineArrayHandle    lineArray;
  80.     SignedByte            weState;
  81.     
  82.     // i don't know how necessary it is to lock the WEHandle and the
  83.     // LineArrayHandle, but considering what we're doing, it can't hurt
  84.     // (tho i'm sure there won't be any interrupt calls here, can't hurt)
  85.     
  86.     weState = HGetState( (Handle)we );
  87.     HLock( (Handle)we );
  88.     
  89.     lineCount = WECountLines( we );
  90.     
  91.     lineArray = (*we)->hLines;
  92.     
  93.     HLock( (Handle)lineArray );
  94.  
  95.     // this for loop was the translation problem *bleck*.  hopefully this is
  96.     // totally right...it seems to work no problem.
  97.     
  98.     for ( x = 1; x <= lineCount; x++ )
  99.      ((*lineArray)[x]).lineOrigin = 2 * ((*lineArray)[x]).lineOrigin;
  100.  
  101.     HUnlock( (Handle)lineArray );
  102.     HSetState((Handle)we, weState );
  103.  
  104.     return;
  105. }
  106.  
  107.  
  108. // here's another way of doing this that Marco Piovanelli sent me:
  109. /*
  110. void SetSpacing( WEHandle hWE )
  111. {
  112.     LinePtr pLine;
  113.     long lineIndex, nLines;
  114.  
  115.     nLines = WECountLines( hWE );
  116.  
  117.     pLine = *(*hWE)->hLines;
  118.     for ( lineIndex = 0; lineIndex < nLines; lineIndex++ )
  119.     {
  120.         pLine->lineOrigin *= 2;
  121.         pLine++;
  122.     }
  123. }
  124. */